/**
 * 
 */
package de.cbf.cam.dsa.model.entities;

import java.beans.PropertyChangeSupport;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.OneToOne;
import javax.persistence.Transient;

import de.cbf.cam.dsa.model.base.TalentTmpl;
import de.cbf.cam.dsa.model.persistence.Header;

/**
 * @author Nebelritter
 *
 */
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
public class OneTalent extends Header {
	/**
	 * @uml.property  name="value"
	 */
	protected Integer value;
	/**
	 * @uml.property  name="owner"
	 * @uml.associationEnd  multiplicity="(1 1)" inverse="talentMap:de.cbf.cam.dsa.model.entities.OneNPC"
	 */
	protected OneNPC owner;
	/**
	 * @uml.property  name="template"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
	protected TalentTmpl template;
	
	public static String PROPERTYNAME = "OneTalent:";	
	/**
	 * @uml.property  name="propertyChangeSupport"
	 */
	public PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
//========================
//		constructors
//========================
	/**
	 * method to initialize object,
	 * provide default values for every field
	 * accessable by all constructors
	 */
	private void init() {

	}

	public OneTalent(TalentTmpl template,OneNPC owner,int value) {
		super();	
		init();
		this.template = template;
		this.owner = owner;
		this.value = value;		
	}

	public OneTalent clone(){
		OneTalent talent = new OneTalent(template,owner,value);		
		return talent;
	}	
	
//========================
//	   public methods
//========================

//========================
//    standard methods
//========================

//========================
// 	   private methods
//========================
//========================
//	getters/setters
//========================
	public Integer getTalValue() {
		return value;
	}
	public void setTalValue(Integer value) {
		this.value = value;
	}	
	/**
	 * @return
	 * @uml.property  name="owner"
	 */
	@OneToOne(cascade=CascadeType.ALL)
	public OneNPC getOwner() {
		return owner;
	}
	/**
	 * @param owner  the owner to set
	 * @uml.property  name="owner"
	 */
	protected void setOwner(OneNPC owner) {
		this.owner = owner;
	}
	
	@Transient
	public String getName(){
		return template.getName();
	}
	
	/**
	 * @return
	 * @uml.property  name="template"
	 */
	@OneToOne(cascade=CascadeType.ALL)
	public TalentTmpl getTemplate(){
		return template;
	}
	/**
	 * @param template  the template to set
	 * @uml.property  name="template"
	 */
	protected void setTemplate(TalentTmpl template) {
		this.template = template;
	}	
//========================
//		listeners
//========================

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;		
		result = prime * result + ((owner == null) ? 0 : owner.hashCode());
		result = prime * result + ((value == null) ? 0 : value.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		OneTalent other = (OneTalent) obj;		
		if (owner == null) {
			if (other.owner != null)
				return false;
		} else if (!owner.equals(other.owner))
			return false;
		if (value == null) {
			if (other.value != null)
				return false;
		} else if (!value.equals(other.value))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return template.getName()+":"+value+"("+owner.toString()+")";
	}

	@Override
	@Id
	public String getGuid() {
		return guid;
	}

	@Override
	protected void setGuid(String guid) {
		this.guid = guid;		
	}

	

	
	
	
}
